package com.yj.blog.admin.service.impl;

import com.yj.blog.admin.service.SysResourceCategoryService;
import com.yj.blog.mapper.SysResourceCategoryMapper;
import com.yj.blog.model.SysResourceCategory;
import com.yj.blog.model.SysResourceCategoryExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 资源分类管理Service实现类
 */
@Service
public class SysResourceCategoryServiceImpl implements SysResourceCategoryService {
    @Autowired
    private SysResourceCategoryMapper resourceCategoryMapper;

    @Override
    public List<SysResourceCategory> listAll() {
        SysResourceCategoryExample example = new SysResourceCategoryExample();
        example.setOrderByClause("sort desc");
        return resourceCategoryMapper.selectByExample(example);
    }

    @Override
    public int create(SysResourceCategory sysResourceCategory) {
        sysResourceCategory.setCreateTime(new Date());
        return resourceCategoryMapper.insert(sysResourceCategory);
    }

    @Override
    public int update(Long id, SysResourceCategory sysResourceCategory) {
        sysResourceCategory.setId(id);
        return resourceCategoryMapper.updateByPrimaryKeySelective(sysResourceCategory);
    }

    @Override
    public int delete(Long id) {
        return resourceCategoryMapper.deleteByPrimaryKey(id);
    }
}
